﻿#region Copyright Notice

//Copyright © 2007-2011, PARROT SA, all rights reserved. 

//DISCLAIMER 
//The APIs is provided by PARROT and contributors "AS IS" and any express or implied warranties, including, but not limited to, the implied warranties of merchantability 
//and fitness for a particular purpose are disclaimed. In no event shall PARROT and contributors be liable for any direct, indirect, incidental, special, exemplary, or 
//consequential damages (including, but not limited to, procurement of substitute goods or services; loss of use, data, or profits; or business interruption) however 
//caused and on any theory of liability, whether in contract, strict liability, or tort (including negligence or otherwise) arising in any way out of the use of this 
//software, even if advised of the possibility of such damage. 

//Author            : Wilke Jansoone
//Email             : wilke.jansoone@digitude.net
//Publishing date   : 28/11/2010 

//Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions
//are met:
//    - Redistributions of source code must retain the above copyright notice, this list of conditions, the disclaimer and the original author of the source code.
//    - Neither the name of the PixVillage Team, nor the names of its contributors may be used to endorse or promote products derived from this software without 
//      specific prior written permission.

#endregion

#region Imports

using System;

using Wilke.Interactive.Drone.Control.Enumerations;

#endregion

namespace Wilke.Interactive.Drone.Control
{
    /// <summary>
    /// This class makes using the <see cref="DroneStatusFlags"/> enumeration easier.
    /// </summary>
    internal class DroneStatusFlagsHelper
    {
        internal DroneStatusFlags DroneStatus { get; set; }

        /// <summary>
        /// Refers to status mask AR_DRONE_FLY_MASK
        /// </summary>
        internal bool IsFlightEnabled
        {
            get{ return GetMask(DroneStatusFlags.AR_DRONE_FLY_MASK); }
        }
        /// <summary>
        /// Refers to status mask AR_DRONE_VIDEO_MASK
        /// </summary>
        internal bool IsVideoEnabled
        {
            get{ return GetMask(DroneStatusFlags.AR_DRONE_VIDEO_MASK); }
        }
        /// <summary>
        /// Refers to status mask AR_DRONE_VISION_MASK
        /// </summary>
        internal bool IsVisionEnabled
        {
            get{ return GetMask(DroneStatusFlags.AR_DRONE_VISION_MASK); }
        }
        /// <summary>
        /// Refers to status mask AR_DRONE_CONTROL_MASK
        /// </summary>
        internal bool IsAngulerSpeedControlEnabled
        {
            get{ return GetMask(DroneStatusFlags.AR_DRONE_CONTROL_MASK); }
        }
        /// <summary>
        /// Refers to status mask AR_DRONE_ALTITUDE_MASK
        /// </summary>
        internal bool IsAltitudeControlEnabled
        {
            get{ return GetMask(DroneStatusFlags.AR_DRONE_ALTITUDE_MASK); }
        }
        /// <summary>
        /// Refers to status mask AR_DRONE_USER_FEEDBACK_START
        /// </summary>
        internal bool IsStartButtonEnabled
        {
            get{ return GetMask(DroneStatusFlags.AR_DRONE_USER_FEEDBACK_START); }
        }
        /// <summary>
        /// Refers to status mask AR_DRONE_COMMAND_MASK
        /// </summary>
        internal bool HasCommandReceived
        {
            get{ return GetMask(DroneStatusFlags.AR_DRONE_COMMAND_MASK); }
        }
        /// <summary>
        /// Refers to status mask AR_DRONE_TRIM_COMMAND_MASK
        /// </summary>
        internal bool HasFlatTrimCommandReceived
        {
            get{ return GetMask(DroneStatusFlags.AR_DRONE_TRIM_COMMAND_MASK); }
        }
        /// <summary>
        /// Refers to status mask AR_DRONE_TRIM_RUNNING_MASK
        /// </summary>
        internal bool IsFlatTrimRunning
        {
            get{ return GetMask(DroneStatusFlags.AR_DRONE_TRIM_RUNNING_MASK); }
        }
        /// <summary>
        /// Refers to status mask AR_DRONE_TRIM_RESULT_MASK
        /// </summary>
        internal bool HasFlatTrimSucceeded
        {
            get{ return GetMask(DroneStatusFlags.AR_DRONE_TRIM_RESULT_MASK); }
        }
        /// <summary>
        /// Refers to status mask AR_DRONE_NAVDATA_DEMO_MASK
        /// </summary>
        internal bool SendAllNavigationData
        {
            get{ return GetMask(DroneStatusFlags.AR_DRONE_NAVDATA_DEMO_MASK); }
        }
        /// <summary>
        /// Refers to status mask AR_DRONE_NAVDATA_BOOTSTRAP
        /// </summary>
        internal bool IsInitialized
        {
            get{ return !GetMask(DroneStatusFlags.AR_DRONE_NAVDATA_BOOTSTRAP); }
        }

        /// <summary>
        /// Refers to status mask AR_DRONE_MOTORS_BRUSHED
        /// </summary>
        internal bool IsUsingBrushedMotors
        {
            get{ return GetMask(DroneStatusFlags.AR_DRONE_MOTORS_BRUSHED); }
        }
        /// <summary>
        /// Refers to status mask AR_DRONE_COM_LOST_MASK
        /// </summary>
        internal bool HasCommunicationLost
        {
            get{ return GetMask(DroneStatusFlags.AR_DRONE_COM_LOST_MASK); }
        }
        /// <summary>
        /// Refers to status mask AR_DRONE_GYROS_ZERO
        /// </summary>
        internal bool HasGyrosProblem
        {
            get{ return GetMask(DroneStatusFlags.AR_DRONE_GYROS_ZERO); }
        }
        /// <summary>
        /// Refers to status mask AR_DRONE_VBAT_LOW
        /// </summary>
        internal bool IsBatteryChargeTooLow
        {
            get{ return GetMask(DroneStatusFlags.AR_DRONE_VBAT_LOW); }
        }
        /// <summary>
        /// Refers to status mask AR_DRONE_VBAT_HIGH
        /// </summary>
        internal bool IsBatteryChargeTooHigh
        {
            get{ return GetMask(DroneStatusFlags.AR_DRONE_VBAT_HIGH); }
        }
        /// <summary>
        /// Refers to status mask AR_DRONE_TIMER_ELAPSED
        /// </summary>
        internal bool HasTimerElapsed
        {
            get{ return GetMask(DroneStatusFlags.AR_DRONE_TIMER_ELAPSED); }
        }
        /// <summary>
        /// Refers to status mask AR_DRONE_NOT_ENOUGH_POWER
        /// </summary>
        internal bool HasNotEnoughPower
        {
            get{ return GetMask(DroneStatusFlags.AR_DRONE_NOT_ENOUGH_POWER); }
        }
        /// <summary>
        /// Refers to status mask AR_DRONE_ANGLES_OUT_OF_RANGE
        /// </summary>
        internal bool AreAnglesOutOfRange
        {
            get{ return GetMask(DroneStatusFlags.AR_DRONE_ANGLES_OUT_OF_RANGE); }
        }
        /// <summary>
        /// Refers to status mask AR_DRONE_WIND_MASK
        /// </summary>
        internal bool TooMuchWind
        {
            get{ return GetMask(DroneStatusFlags.AR_DRONE_WIND_MASK); }
        }
        /// <summary>
        /// Refers to status mask AR_DRONE_ULTRASOUND_MASK
        /// </summary>
        internal bool HasUltraSoundProblem
        {
            get{ return GetMask(DroneStatusFlags.AR_DRONE_ULTRASOUND_MASK); }
        }
        /// <summary>
        /// Refers to status mask AR_DRONE_ATCODEC_THREAD_ON
        /// </summary>
        internal bool HasActiveATCommandThread
        {
            get{ return GetMask(DroneStatusFlags.AR_DRONE_ATCODEC_THREAD_ON); }
        }
        /// <summary>
        /// Refers to status mask AR_DRONE_NAVDATA_THREAD_ON
        /// </summary>
        internal bool HasActiveNavigationDataThread
        {
            get{ return GetMask(DroneStatusFlags.AR_DRONE_NAVDATA_THREAD_ON); }
        }
        /// <summary>
        /// Refers to status mask AR_DRONE_VIDEO_THREAD_ON
        /// </summary>
        internal bool HasActiveVideoStreamThread
        {
            get{ return GetMask(DroneStatusFlags.AR_DRONE_VIDEO_THREAD_ON); }
        }
        /// <summary>
        /// Refers to status mask AR_DRONE_COM_WATCHDOG_MASK
        /// </summary>
        internal bool HasCommunicationProblem
        {
            get{ return GetMask(DroneStatusFlags.AR_DRONE_COM_WATCHDOG_MASK); }
        }

        /// <summary>
        /// Refers to status mask AR_DRONE_EMERGENCY_MASK
        /// </summary>
        internal bool HasEmergency
        {
            get{ return GetMask(DroneStatusFlags.AR_DRONE_EMERGENCY_MASK); }
        }

        #region Attributes not yet understood

        internal bool AR_DRONE_CUTOUT_MASK
        {
            get{ return GetMask(DroneStatusFlags.AR_DRONE_CUTOUT_MASK); }
        }
        internal bool AR_DRONE_PIC_VERSION_MASK
        {
            get{ return GetMask(DroneStatusFlags.AR_DRONE_PIC_VERSION_MASK); }
        }
        internal bool AR_DRONE_ACQ_THREAD_ON
        {
            get{ return GetMask(DroneStatusFlags.AR_DRONE_ACQ_THREAD_ON); }
        }
        internal bool AR_DRONE_CTRL_WATCHDOG_MASK
        {
            get{ return GetMask(DroneStatusFlags.AR_DRONE_CTRL_WATCHDOG_MASK); }
        }
        internal bool AR_DRONE_ADC_WATCHDOG_MASK
        {
            get{ return GetMask(DroneStatusFlags.AR_DRONE_ADC_WATCHDOG_MASK); }
        }

        #endregion

        #region Private Methods

        private bool GetMask(DroneStatusFlags droneStatusFlags)
        {
            return (((DroneStatusFlags)DroneStatus & droneStatusFlags) == droneStatusFlags);
        }

        #endregion
    }
}
